/*
 *  This file is part of LifeBudget - Copyright 2010 Clifton Eaton
 *  ------------------------------------------------------------------
 *  LifeBudget is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  LifeBudget is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with LifeBudget.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.lifebudget.app.client.mvc.view;

import org.lifebudget.app.client.events.AppEvents;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.View;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;

/**
 * The Class TabView creates the tabbed view containing the four 
 * application tabs, Overview, Transaction Journal, Paycheck Calculators, 
 * and Categories.
 */
public class TabView extends View {

	/** The property string for retrieving the Transactions Tab object from the {@link Registry}. */
	public static String TRANSACTIONS_TAB = "TransactionJournalTab";
	
	/** The property string for retrieving the Categories Tab object from the {@link Registry}. */
	public static String CATEGORIES_TAB = "CategoriesTab";
	
	/** The property string for retrieving the Overview Tab object from the {@link Registry}. */
	public static String OVERVIEW_TAB = "OverviewTab";
	
	/** The property string for retrieving the PaycheckCalculator Tab object from the {@link Registry}. */
	public static String PAYCHECK_CALC_TAB = "PaycheckCalculatorTab";

	/** The center. */
	private LayoutContainer center;
	
	/** The folder. */
	private TabPanel folder;
	
	/** The transactions {@link TabItem}. */
	private TabItem transactions;
	
	/** The paycheck calc {@link TabItem}. */
	private TabItem paycheckCalc;
	
	/** The overview {@link TabItem}. */
	private TabItem overview;
	
	/** The categories {@link TabItem}. */
	private TabItem categories;

	/**
	 * Instantiates a new tab view.
	 *
	 * @param controller the controller
	 */
	public TabView(Controller controller) {
		super(controller);

	}

	/* (non-Javadoc)
	 * @see com.extjs.gxt.ui.client.mvc.View#initialize()
	 */
	public void initialize() {

	}

	/**
	 * Handles the <code>Init</code> event, laying out the tab view, creating the folders
	 * and placing references to them in the {@link Registry}.
	 */
	public void initUI() {
		// get the reference to the center panel in the appview
		center = (LayoutContainer) Registry.get(AppView.CENTER_PANEL);

		// create the tab control
		folder = new TabPanel();
		folder.setPlain(true);



		// **** INSERT FIRST TAB HERE *********

		transactions = new TabItem("Transactions");
		transactions.setLayout(new FitLayout());
		folder.add(transactions);
		Registry.register(TRANSACTIONS_TAB, transactions);

		// ************************************
		categories = new TabItem("Categories");
		categories.setLayout(new FitLayout());
		folder.add(categories);
		Registry.register(CATEGORIES_TAB, categories);

		paycheckCalc = new TabItem("Paycheck Calculator");
		paycheckCalc.setLayout(new FitLayout());
		folder.add(paycheckCalc);
		Registry.register(PAYCHECK_CALC_TAB, paycheckCalc);
		
		overview = new TabItem("Overview");
		// overview.setLayout(new FitLayout());
		folder.add(overview);
		Registry.register(OVERVIEW_TAB, overview);
		
		// GWT.log("Adding Tab Panel to center Layout Container");
		center.add(folder);
		center.layout();
	}

	/* (non-Javadoc)
	 * @see com.extjs.gxt.ui.client.mvc.View#handleEvent(com.extjs.gxt.ui.client.mvc.AppEvent)
	 */
	@Override
	protected void handleEvent(AppEvent event) {
		if (event.getType() == AppEvents.Init) {
			// GWT.log("TabView handling Init");
			initUI();
		}

	}

}
